package com.ruoyi.kucun.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kucun.domain.InventoryAlert;
import com.ruoyi.kucun.service.IInventoryAlertService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存预警阈值设置Controller
 * 
 * @author Rosou
 * @date 2025-06-17
 */
@Controller
@RequestMapping("/kucun/alert")
public class InventoryAlertController extends BaseController
{
    private String prefix = "kucun/alert";

    @Autowired
    private IInventoryAlertService inventoryAlertService;

    @RequiresPermissions("kucun:alert:view")
    @GetMapping()
    public String alert()
    {
        return prefix + "/alert";
    }

    /**
     * 查询库存预警阈值设置列表
     */
    @RequiresPermissions("kucun:alert:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(InventoryAlert inventoryAlert)
    {
        startPage();
        List<InventoryAlert> list = inventoryAlertService.selectInventoryAlertList(inventoryAlert);
        return getDataTable(list);
    }

    /**
     * 导出库存预警阈值设置列表
     */
    @RequiresPermissions("kucun:alert:export")
    @Log(title = "库存预警阈值设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(InventoryAlert inventoryAlert)
    {
        List<InventoryAlert> list = inventoryAlertService.selectInventoryAlertList(inventoryAlert);
        ExcelUtil<InventoryAlert> util = new ExcelUtil<InventoryAlert>(InventoryAlert.class);
        return util.exportExcel(list, "库存预警阈值设置数据");
    }

    /**
     * 新增库存预警阈值设置
     */
    @RequiresPermissions("kucun:alert:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存预警阈值设置
     */
    @RequiresPermissions("kucun:alert:add")
    @Log(title = "库存预警阈值设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(InventoryAlert inventoryAlert)
    {
        return toAjax(inventoryAlertService.insertInventoryAlert(inventoryAlert));
    }

    /**
     * 修改库存预警阈值设置
     */
    @RequiresPermissions("kucun:alert:edit")
    @GetMapping("/edit/{alertId}")
    public String edit(@PathVariable("alertId") Long alertId, ModelMap mmap)
    {
        InventoryAlert inventoryAlert = inventoryAlertService.selectInventoryAlertByAlertId(alertId);
        mmap.put("inventoryAlert", inventoryAlert);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存预警阈值设置
     */
    @RequiresPermissions("kucun:alert:edit")
    @Log(title = "库存预警阈值设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InventoryAlert inventoryAlert)
    {
        return toAjax(inventoryAlertService.updateInventoryAlert(inventoryAlert));
    }

    /**
     * 删除库存预警阈值设置
     */
    @RequiresPermissions("kucun:alert:remove")
    @Log(title = "库存预警阈值设置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(inventoryAlertService.deleteInventoryAlertByAlertIds(ids));
    }
}
